﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using DevExpress.XtraBars.Localization;
using DevExpress.XtraTab;
using DevExpress.LookAndFeel;
using DevExpress.Skins;
using DevExpress.UserSkins;

namespace RapChieuPhim.GUI
{
    public partial class formMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public formMain()
        {
            BonusSkins.Register();
            InitializeComponent();
        }

        private void formMain_Load(object sender, EventArgs e)
        {
            initSkinsHelp();
            btnLogout.Enabled = false;

            Modules.Login _login = new Modules.Login();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabLogin", "Đăng nhập", _login);

            _login.ShowHideControl += new Modules.LoadPhanQuyen(ShowHideControl);

        }

        #region init All
        private void initSkinsHelp()
        {
            SkinHelper.InitSkinGallery(ribbonGalleryBarItem1, true);
            UserLookAndFeel.Default.SkinName = "Money Twins";
        }


        #endregion

        #region Show/Hide Controls
        private void ShowHideControl(Boolean _flag, int _typeOfLogin)
        {
            if (_flag)
            {
                btnLogin.Enabled = false;
                btnLogout.Enabled = true;
                TabControlMain.TabPages.RemoveAt(TabControlMain.SelectedTabPageIndex);

                switch (_typeOfLogin)
                {
                    case 0: // Admin
                        ResetShowHide();
                        ribPageAccount.Visible = _flag;
                        ribPageQLRap.Visible = _flag;
                        PageGroupQLCa.Visible = _flag;
                        PageGroupQLPhim.Visible = _flag;
                        PageGroupQLPhong.Visible = _flag;
                        PageGroupQLRap.Visible = _flag;
                        PageGroupBanVe.Visible = _flag;
                        pageGiaTri.Visible = _flag;
                        barButtonNhanVien.Visibility = BarItemVisibility.Always;
                        barButtonAllAcc.Visibility = BarItemVisibility.Always;
                        ribbon.SelectedPage = ribPageAccount;
                        break;
                    case 1: //Trưởng
                        ResetShowHide();
                        ribPageAccount.Visible = _flag;
                        ribPageQLRap.Visible = _flag;
                        PageGroupQLPhim.Visible = _flag;
                        PageGroupQLPhong.Visible = _flag;
                        pageGiaTri.Visible = _flag;
                        barButtonNhanVien.Visibility = BarItemVisibility.Always;
                        ribbon.SelectedPage = ribPageAccount;
                        break;
                    case 2: //Quản lí
                        ResetShowHide();
                        ribPageAccount.Visible = _flag;
                        ribPageQLRap.Visible = _flag;
                        PageGroupQLCa.Visible = _flag;
                        ribbon.SelectedPage = ribPageAccount;
                        break;
                    case 3: //Nhân viên
                        ResetShowHide();
                        ribPageAccount.Visible = _flag;
                        PageGroupBanVe.Visible = _flag;
                        ribbon.SelectedPage = ribPageAccount;
                        break;
                    case 4: //Member
                        ResetShowHide();
                        ribbon.SelectedPage = ribPageQLVe;
                        break;
                }
            }
            else
            {
                Application.Restart();
            }
        }

        private void ResetShowHide()
        {
            ribPageAccount.Visible = false;
            ribPageQLRap.Visible = false;
            PageGroupQLCa.Visible = false;
            PageGroupQLPhim.Visible = false;
            PageGroupQLPhong.Visible = false;
            PageGroupQLRap.Visible = false;
            PageGroupBanVe.Visible = false;
            pageGiaTri.Visible = false;
            barButtonNhanVien.Visibility = BarItemVisibility.Never;
            barButtonAllAcc.Visibility = BarItemVisibility.Never;
        }

        #endregion

        private void TabControlMain_ControlAdded(object sender, ControlEventArgs e)
        {
            TabControlMain.SelectedTabPageIndex = TabControlMain.TabPages.Count - 1;
        }

        private void TabControlMain_CloseButtonClick(object sender, EventArgs e)
        {
            TabControlMain.TabPages.RemoveAt(TabControlMain.SelectedTabPageIndex);
            TabControlMain.SelectedTabPageIndex = TabControlMain.TabPages.Count - 1;
        }

        private void barButtonAccCard_ItemClick(object sender, ItemClickEventArgs e)
        {
            Modules.MemberCard _NewModules = new Modules.MemberCard();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabMemberCard", "Thẻ thành viên", _NewModules);
        }


        private void barButtonAllAcc_ItemClick(object sender, ItemClickEventArgs e)
        {
            
        }

        private void btnThongTinPhim_ItemClick(object sender, ItemClickEventArgs e)
        {
            GUI.InfoMovie _NewModules = new GUI.InfoMovie();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabInfoMovie", "Thông tin phim", _NewModules);
        }

        private void btnLichChieuPhim_ItemClick(object sender, ItemClickEventArgs e)
        {
            
        }

        private void btnBanVe_ItemClick(object sender, ItemClickEventArgs e)
        {
            GUI.BanVeGUI _NewModules = new GUI.BanVeGUI();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabBanVe", "Thông tin bán vé", _NewModules);
        }

        private void btnDatVe_ItemClick(object sender, ItemClickEventArgs e)
        {
            GUI.DatVeGUI _NewModules = new GUI.DatVeGUI();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabDatVe", "Đặt vé", _NewModules);
        }

        private void btnQLRap_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void btnLogout_ItemClick(object sender, ItemClickEventArgs e)
        {
            ShowHideControl(true, 4);
            btnLogin.Enabled = true;
            btnLogout.Enabled = false;
        }

        private void btnLogin_ItemClick(object sender, ItemClickEventArgs e)
        {
            Modules.Login _login = new Modules.Login();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabLogin", "Đăng nhập", _login);

            _login.ShowHideControl += new Modules.LoadPhanQuyen(ShowHideControl);
        }

        private void barButtonChangePass_ItemClick(object sender, ItemClickEventArgs e)
        {
            Modules.InfoAdmin _NewModules = new Modules.InfoAdmin();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabInfoAdmin", "Thay đổi mật khẩu", _NewModules);
        }

        private void barButtonProfile_ItemClick(object sender, ItemClickEventArgs e)
        {
            GUI.Profile _NewModules = new GUI.Profile();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabProfile", "Thông tin cá nhân", _NewModules);
        }

        private void barButtonNhanVien_ItemClick(object sender, ItemClickEventArgs e)
        {
            Modules.InfoAllAgent _NewModules = new Modules.InfoAllAgent();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabInfoAllAgent", "Thông tin nhân viên", _NewModules);
        }

        private void barbtnAbout_ItemClick(object sender, ItemClickEventArgs e)
        {
            Modules.About _about = new Modules.About();
            Class.ClassAddNewTab _NewTab0 = new Class.ClassAddNewTab();
            _NewTab0.AddTab(TabControlMain, "TabMap", "Thông tin", _about);
        }

        private void barbtnDinhGia_ItemClick(object sender, ItemClickEventArgs e)
        {
            GUI.GiaTri _NewModules = new GUI.GiaTri();
            Class.ClassAddNewTab _NewTab = new Class.ClassAddNewTab();
            _NewTab.AddTab(TabControlMain, "TabDinhGia", "Định giá vé", _NewModules);
        }
    }
}